package utoday.service;

import java.util.Map;

import org.slim3.datastore.Datastore;
import org.slim3.util.BeanUtil;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.Transaction;

import utoday.meta.SettingMeta;
import utoday.model.Setting;


public class SettingService {

    public Setting settingInfo(Map<String, Object> input) {
        Setting settingInfo = new Setting();
        BeanUtil.copy(input, settingInfo);
        Transaction tx = Datastore.beginTransaction();

        Datastore.put(settingInfo);
        tx.commit();
        return settingInfo;
    }

    public void updateSetting(Key key, Setting inputSettingInfo) {
        Setting settingInfo = Datastore.get(Setting.class, key);
        settingInfo.setCity(inputSettingInfo.getCity());
        Datastore.put(settingInfo);
    }

    private SettingMeta t = new SettingMeta();

    public Setting getSettingInfo() {
        return Datastore.query(t).sort(t.city.desc).asSingle();
    }
}
